<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.${className}Mapper">

    <select id="page${className}ByIdOrder" resultType="${basePackageName}entity.${className}">
        SELECT
            k.*
        FROM
            ${tableName} AS k
        INNER JOIN
            (SELECT id FROM ${tableName}) AS t1
        ON
            k.id=t1.id
    </select>

    <select id="page${className}Mapper" resultType="${basePackageName}entity.${className}">
        SELECT
            k.*
        FROM
            ${tableName} AS k
        INNER JOIN
            (SELECT id
             FROM
                ${tableName}
            <where>
    <#list fields as field>
        <#if field.type == "String">
            <#if field.sType == "2">
                <if test="${field.name} != null and ${field.name} != ''">
                    and JSON_CONTAINS(${field.tableColumnName},  <#noparse>#{</#noparse>${field.name}})
                </if>
<!--                <if test="${field.name} != null and ${field.name} != ''">-->
<!--                    and JSON_EXTRACT(${field.tableColumnName}, '$.itemId') = <#noparse>#{</#noparse>${field.name}} -->
<!--                </if>-->
            <#else >
                <if test="${field.name} != null and ${field.name} != ''">
                    and ${field.tableColumnName} = <#noparse>#{</#noparse>${field.name}}
                </if>
            </#if>
        <#else >
                <if test="${field.name} != null">
                    and ${field.tableColumnName} = <#noparse>#{</#noparse>${field.name}}
                </if>
        </#if>
    </#list>
            </where>
            ORDER BY
                ${fieldTableOrderBy} desc
            ) AS t1
        ON
            k.id=t1.id
    </select>

</mapper>
